package com.jqq.set_;

import java.util.HashSet;
import java.util.Objects;

/**
 * @author 姬倩倩
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class HashSetExercise02 {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        Employee1 jqq1 = new Employee1("jqq", 12000, new MyDate(2000, 12, 7));
        Employee1 jqq2 = new Employee1("jqq", 14000, new MyDate(2000, 12, 7));
        Employee1 jack = new Employee1("yack", 12000, new MyDate(2000, 12, 7));
        System.out.println(hashSet.add(jqq1));//true
        System.out.println(hashSet.add(jqq1));//false
        System.out.println(hashSet.add(jqq2));//false
        System.out.println(hashSet.add(jack));//true
    }
}

class Employee1{
    private String name;
    private double sal;
    private MyDate date;

    public Employee1(String name, double sal, MyDate date) {
        this.name = name;
        this.sal = sal;
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getDate() {
        return date;
    }

    public void setDate(MyDate date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Employee1{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", date=" + date +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee1 employee1 = (Employee1) o;
        return Objects.equals(name, employee1.name) &&
                Objects.equals(date, employee1.date);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, date);
    }
}
class MyDate{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year &&
                month == myDate.month &&
                day == myDate.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }
}